package com.itheima.server.controller;

import com.itheima.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {
    @Autowired
    private UserService userService;
    /*手机号登陆
    * Spring提供的ResponseEntity我们用于响应数据
    * post请求，请求头是phone
    * */
    @PostMapping("/login")
    public Object login(@RequestBody Map map){
        String mobile = (String) map.get("phone");
        userService.sendMsg(mobile);
        return ResponseEntity.ok(null);
    }
    /*验证码校验
    post请求，请求头是phone,verificationCode
    * */
    @PostMapping("/loginVerification")
    public ResponseEntity loginVerification(@RequestBody Map map){
        String phone = (String)map.get("phone");
        String code = (String)map.get("verificationCode");
        Map resMap = userService.loginVerification(phone, code);
        return ResponseEntity.ok(resMap);
    }
}
